﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.DALFactory;
using System.Data;
using AspNetCs.Model;

namespace AspNetCs.Bll
{
    public class Alms_BLL
    {
        private IAlms CreateAlms = Conn.CreateAlms();

        public DataTable GetDataTable(string filter)
        {
            return CreateAlms.GetDataTable(filter);
        }

        public Alms_Model GetModel(DataRow dr)
        {
            return CreateAlms.GetModel(dr);
        }
        public Alms_Model GetModel(int id)
        {
            Alms_Model m = new Alms_Model();
            DataTable dt = GetDataTable(" id=" + id);
            foreach (DataRow dr in dt.Rows)
            {
                m = GetModel(dr);
            }

            return m;
        }

        public int Add(Alms_Model md)
        {
            return CreateAlms.Add(md);
        }

        /// <summary>
        /// 捐助添加
        /// </summary>
        /// <param name="AlmsObj">捐助的对象</param>
        /// <param name="DefaultMail">默认邮箱</param>
        /// <param name="typeid">ID</param>
        /// <param name="channleid">频道</param>
        /// <returns></returns>
        public String AlmsAdd(string AlmsObj, string DefaultMail, string typeid, string channleid, string formurl,string ReUrl)
        {
            #region 捐助

            StringBuilder stb = new StringBuilder();

            stb.AppendLine("<script>$(document).ready(function(){");

            stb.AppendLine("$(\"#Point\").click(function(){");

            stb.AppendLine("if($(\"#GDName\").val()==\"\"){alert('捐款姓名不能为空!');$(\"#GDName\").focus();return false;};");
            stb.AppendLine("if($(\"#GDmoney\").val()==\"\"){alert('捐款金额必须大于1元');$(\"#GDmoney\").focus();return false;};");

            stb.AppendLine("$(\"#AlmsTypes\").val('1');");

            stb.AppendLine("$(\"#FormAlms\").submit();  });");



            stb.AppendLine("$(\"#BlankObj\").click(function(){");

            stb.AppendLine("if($(\"#GDName\").val()==\"\"){alert('捐款姓名不能为空!');$(\"#GDName\").focus();return false;}");
            stb.AppendLine("if($(\"#GDmoney\").val()==\"\"){alert('捐款金额必须大于1元');$(\"#GDmoney\").focus();return false;}");
            stb.AppendLine("$(\"#AlmsTypes\").val('2');");         
            stb.AppendLine("$(\"#FormAlms\").submit();  });");




            stb.AppendLine("$(\"#FormAlms\").submit(function(){");

            stb.AppendLine("if($(\"#GDName\").val()==\"\"){alert('捐款姓名不能为空!');$(\"#GDName\").focus();return false;}");
            stb.AppendLine("if($(\"#GDmoney\").val()==\"\"){alert('捐款金额必须大于1元');$(\"#GDmoney\").focus();return false;}");
            stb.AppendLine(" });");




            stb.AppendLine("})</script>");

            stb.AppendLine("<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>");
            stb.AppendLine("<form name='FormAlms' id='FormAlms' method='post' action='" + formurl + "'>");
            stb.AppendLine("<tr>");
            stb.AppendLine("<td valign='top' style='border-bottom:1px dashed #CCCCCC'  colspan=4><img src='/Images/gongde_3_02.gif' height=40/></td>");
            stb.AppendLine("</tr>");

            stb.AppendLine("<tr>");

            stb.AppendLine("<td valign='top' style='border-bottom:1px dashed #CCCCCC'  colspan=4>");
            stb.AppendLine("</td></tr>");
            stb.AppendLine("<tr ><td valign='top'></td>");

            stb.AppendLine("</tr><tr >");

            stb.AppendLine("<td valign='top'  colspan=4>");
            stb.AppendLine("<table width='100%' border='0' cellspacing='3' cellpadding='2' align=center>");
            stb.AppendLine("<tr><td><input type='hidden' id='AlmsTypes' name='AlmsTypes' value='2'> <input type='hidden' id='ChannelId' name='ChannelId' value='" + channleid + "'> <input type='hidden' id='ActionType' name='ActionType' value='SaveAlms'><input type='hidden' id='meid' name='meid' value='" + typeid + "'>捐款姓名:<input type='text' id='GDName' name='GDName'><span style='color:red'>**</span>");
            stb.AppendLine("</td><td>");
            stb.AppendLine("电子邮箱:<input type='text' name='Txt_Mail' id='Txt_Mail' value='" + DefaultMail + "' >");
            stb.AppendLine("</td></tr>");
            stb.AppendLine("<tr><td>捐款对象:" + AlmsObj);
            stb.AppendLine("</td><td>");
            stb.AppendLine("捐款金额:<input type='text' id='GDmoney' name='GDmoney' size=5 maxlength=4 value='100'>元(1-5000)");
            stb.AppendLine("</td></tr>");
            stb.AppendLine("<tr><td colspan=2>");
            stb.AppendLine("说明: <textarea name='GDContent' cols='60' rows='5'></textarea>");
            stb.AppendLine("</td></tr>");
            stb.AppendLine("<tr><td  colspan=2 align=center>");
            stb.AppendLine("<input  type='hidden' id='ReUrlAdr' name='ReUrlAdr' value='" + ReUrl + "'><input type='button' id='Point' name='Point' value='用户扣点'>&nbsp;&nbsp;<input type='button' id='BlankObj' name='BlankObj' value='银行捐款'>");
            stb.AppendLine("</td></tr>");
            stb.AppendLine("</table><br />");
            stb.AppendLine("</td></tr></form></table>");
            #endregion
            return stb.ToString();
        }



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public int Delete(string filter)
        {
            return CreateAlms.Delete(filter);
        }

        /// <summary>
        /// 设置支付
        /// </summary>
        /// <param name="isPay"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public int setPay(int isPay, string filter)
        {
            return CreateAlms.setPay(isPay,filter);
        }

    }
}
